﻿using BootstrapBlazor.Components;

using SqlSugar;

using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Application.Core.Entity;
	
[SugarTable("Permission", TableDescription = "权限表")]
public class Permission
{
	/// <summary>主键 Id</summary>
	[SugarColumn(IsPrimaryKey = true, IsIdentity = true, ColumnDescription = "主键Id")]
	[Display(Name = "主键Id")]
	[AutoGenerateColumn(Ignore = true)]
	public int Id { get; set; }

	/// <summary>权限编码（如：User.Read）</summary>
	[SugarColumn(Length = 64, IsNullable = false, ColumnDescription = "权限编码（如：\\user-manage）")]
	[Display(Name = "权限编码")]
	public string Code { get; set; } = default!;

	/// <summary>权限名称</summary>
	[SugarColumn(Length = 128, IsNullable = false, ColumnDescription = "权限名称")]
	[Display(Name = "权限名称")]
	public string Name { get; set; } = default!;

	/// <summary>权限描述</summary>
	[SugarColumn(Length = 256, IsNullable = true, ColumnDescription = "权限描述")]
	[Display(Name = "权限描述")]
	public string Description { get; set; }

	/// <summary>归属用户Id（可空，不影响多对多关系）</summary>
	[SugarColumn(IsNullable = true, ColumnDescription = "归属用户Id（可空）")]
	[AutoGenerateColumn(Ignore = true)]
	public int? OwnerUserId { get; set; }

	/// <summary>多对多：拥有该权限的用户集合</summary>
	[Navigate(typeof(UserPermission), nameof(UserPermission.PermissionId), nameof(UserPermission.UserId))]
	public List<User> Users { get; set; } = [];
}
